package logic

import (
	"svvenus/vgame/model"
	"svvenus/vpub/constants"
	"svvenus/zlog"
)

var (
	ServerData = new(model.ServerDoc) //服务器数据
)

// ServerLoad
// @Description: 服务器读档
func ServerLoad() {
	db := constants.MgoMain.New()
	defer db.Close()

	err := db.GetId(ServerData)
	if err != nil {
		zlog.Warn("服务器存档为空！ 初始化！")
		ServerData = new(model.ServerDoc)
		_ = db.Save(ServerData, true)
	}else {
		zlog.Warn("服务器存档读取成功！")
		zlog.Info(ServerData)
	}

	//全局邮件读档
	GlobalMailLoadAll()
}

// ServerSave
// @Description: 服务器存档
func ServerSave() {
	db := constants.MgoMain.New()
	defer db.Close()

	_ = db.Save(ServerData, false)

	//全局邮件存档
	GlobalMailSaveAll()
	//玩家存档
	PlayerSaveAll()
}
